home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1995 April / Internet Tools.iso / infoserv / gopher / Unix / xvgopher / v0.5beta / xvgopher.shar.01.Z / xvgopher.shar.01 / GWDirectory.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-25  |  9.4 KB  |  392 lines

  1. //
  2. // GWDirectory.cc
  3. //
  4. // (c) Copyright 1993, San Diego State University -- College of Sciences
  5. //       (See the COPYRIGHT file for more Copyright information)
  6. //
  7. //   This  file  contains  the  routines  of the GWDirectory class which
  8. //   deal with the opening of windows.
  9. //
  10. #include "GWDirectory.h"
  11. #include "xvgopher.h"
  12. #include "GWBookmarks.h"
  13. #include "GWPref.h"
  14. #include "GWAbout.h"
  15. #include "GWGopher.h"
  16. #include <xview/notice.h>
  17. #include <stream.h>
  18. #include <string.h>
  19.  
  20.  
  21. #define    KEY_SAVE_BTN        30010
  22. #define    KEY_SAVE_TXT        30011
  23.  
  24.  
  25. //***************************************************************************
  26. // GWDirectory::GWDirectory(Frame par)
  27. //
  28. GWDirectory::GWDirectory(Frame par)
  29. {
  30.     parent = par;
  31. }
  32.  
  33.  
  34. //***************************************************************************
  35. // int GWDirectory::open(Response *resp)
  36. // PURPOSE:
  37. //   This  will  create a window in which a gopher directory will be
  38. //   displayed.  There  is a special case for this window: it can be
  39. //   the  first  window  created  for  this  program.  Hence, if the
  40. //   parent  is  NULL, the window will NOT be a command window but a
  41. //   regular window.
  42. //
  43. int GWDirectory::open(Response *resp)
  44. {
  45.     //
  46.     // Let the base class create the window.  We will only add the buttons
  47.     //
  48.     if (GWList::open(resp) != OK)
  49.         return NOTOK;
  50.  
  51.     int    left = 8;        // Position of leftmost button in window
  52.     if (!parent)
  53.     {
  54.         //
  55.         //   The main frame gets the Gopher menu button and the Quit
  56.         //   button
  57.         //
  58.         Menu menu = (Menu) xv_create(NULL, MENU,
  59.             MENU_NOTIFY_PROC,                menu_proc,
  60.             MENU_ITEM,
  61.                 MENU_STRING,                "Bookmarks...",
  62.                 NULL,
  63.             MENU_ITEM,
  64.                 MENU_STRING,                "Another Gopher...",
  65.                 NULL,
  66.             MENU_ITEM,
  67.                 MENU_STRING,                "",
  68.                 MENU_FEEDBACK,                FALSE,
  69.                 NULL,
  70.             MENU_ITEM,
  71.                 MENU_STRING,                "Preferences...",
  72.                 NULL,
  73.             MENU_ITEM,
  74.                 MENU_STRING,                "",
  75.                 MENU_FEEDBACK,                FALSE,
  76.                 NULL,
  77.             MENU_ITEM,
  78.                 MENU_STRING,                "About...",
  79.                 NULL,
  80.             XV_KEY_DATA,                    KEY_GWINDOW,    this,
  81.             NULL);
  82.         xv_create(panel, PANEL_BUTTON,
  83.             XV_X,                            8,
  84.             XV_Y,                            8,
  85.             PANEL_LABEL_STRING,                "Gopher",
  86.             PANEL_ITEM_MENU,                menu,
  87.             NULL);
  88.  
  89.         //
  90.         //   Since  we  still  want  to put the other buttons in this panel,
  91.         //   we  need  to  make  sure  they  do  not overlap. That's why the
  92.         //   variable 'left' has the pixel location of the next button.
  93.         //
  94.         left = 92;
  95.  
  96.         //
  97.         // Since we are the parent of all windows, there is only one of us.  Therefore,
  98.         // this is a good place to create the book marks window.
  99.         // The Response parameter to the open member is really a dummy.
  100.         //
  101.         bookmarks = new GWBookmarks(frame);
  102.         bookmarks->open(resp);
  103.  
  104.         //
  105.         // The same holds true for the preferences window...
  106.         //
  107.         gwpref = new GWPref(frame);
  108.         gwpref->open(resp);
  109.     }
  110.  
  111. #if        USE_SAVE
  112.     //
  113.     // Create the save button and save text field.
  114.     //
  115.     Panel_item save_btn = (Panel_item) xv_create(panel, PANEL_BUTTON,
  116.         XV_X,                            left,
  117.         XV_Y,                            8,
  118.         PANEL_LABEL_STRING,                "Save",
  119.         PANEL_INACTIVE,                    TRUE,
  120.         NULL);
  121.     Panel_item save_txt = (Panel_item) xv_create(panel, PANEL_TEXT,
  122.         XV_X,                            left + 56,
  123.         XV_Y,                            8,
  124.         PANEL_LABEL_STRING,                "Save in:",
  125.         PANEL_VALUE_DISPLAY_WIDTH,        260,
  126.         PANEL_INACTIVE,                    TRUE,
  127.         NULL);
  128.  
  129.     xv_set(dir_list,
  130.         XV_KEY_DATA,                    KEY_SAVE_BTN,    save_btn,
  131.         XV_KEY_DATA,                    KEY_SAVE_TXT,    save_txt,
  132.         NULL);
  133. #endif    USE_SAVE
  134.  
  135.     //
  136.     //   Now  some  things  which  need  to  be  set for both FRAMEs and
  137.     //   FRAME_CMDs
  138.     //
  139.     xv_set(frame,
  140.         XV_SHOW,                        TRUE,
  141.         FRAME_RIGHT_FOOTER,                info->get_server(),
  142.         FRAME_DONE_PROC,                done_proc,
  143.         NULL);
  144.  
  145.     //
  146.     // Modify the list menu
  147.     //
  148.     modify_list_menu();
  149.  
  150.     //
  151.     //   Let the user know that we are working on something...
  152.     //
  153.     frame_busy(frame);
  154.  
  155.     //
  156.     //   Now we need to build the connection and get information from it
  157.     //
  158.     gopher = new Gopher(this);
  159.     if (gopher->open(info->get_server(), info->get_port()) == NOTOK)        // Connection
  160.     {
  161.         xv_create(frame, NOTICE,
  162.             NOTICE_MESSAGE_STRINGS,        "Unable to connect to remote gopher",
  163.                                         info->get_server(),
  164.                                         NULL,
  165.             NOTICE_BUTTON_YES,            "Bummer",
  166.             NOTICE_BLOCK_THREAD,        TRUE,
  167.             NOTICE_LOCK_SCREEN,            TRUE,
  168.             XV_SHOW,                    TRUE,
  169.             NULL);
  170.         return NOTOK;
  171.     }
  172.     gopher->read(info->get_type(), info->get_command());                    // Get info
  173.  
  174.     return OK;
  175. }
  176.  
  177.  
  178. //***************************************************************************
  179. // void GWDirectory::modify_list_menu()
  180. //   Modify the Directory List menu so that if contains the following items:
  181. //        Set bookmark
  182. //        Show item info
  183. //
  184. void GWDirectory::modify_list_menu()
  185. {
  186.     //
  187.     // We want to modify the scrolling list's menu, so we need to get it,
  188.     // add the items and then put it back.
  189.     //
  190.     Menu    m = (Menu) xv_get(dir_list, PANEL_ITEM_MENU);
  191.     bookmark_mi = (Menu_item) xv_create(NULL, MENUITEM,
  192.         MENU_STRING,                    "Set bookmark",
  193.         MENU_NOTIFY_PROC,                set_bookmark_proc,
  194.         MENU_INACTIVE,                    TRUE,
  195.         XV_KEY_DATA,                    KEY_GWINDOW, this,
  196.         NULL);
  197.     xv_set(m,
  198.         MENU_APPEND_ITEM,                bookmark_mi,
  199.         NULL);
  200.     show_info_mi = (Menu_item) xv_create(NULL, MENUITEM,
  201.         MENU_STRING,                    "Show item info",
  202.         MENU_NOTIFY_PROC,                show_item_info_proc,
  203.         MENU_INACTIVE,                    TRUE,
  204.         XV_KEY_DATA,                    KEY_GWINDOW, this,
  205.         NULL);
  206.     xv_set(m,
  207.         MENU_APPEND_ITEM,                show_info_mi,
  208.         NULL);
  209.     xv_set(dir_list,
  210.         PANEL_ITEM_MENU,                m,
  211.         NULL);
  212. }
  213.  
  214.  
  215. //***************************************************************************
  216. // void GWDirectory::row_deselect(int, Response *)
  217. //
  218. void GWDirectory::row_deselect(int, Response *)
  219. {
  220. #if        USE_SAVE
  221.     //
  222.     // Hide the button and the text item
  223.     //
  224.     Panel_item        save_btn = (Panel_item) xv_get(dir_list, XV_KEY_DATA, KEY_SAVE_BTN);
  225.     Panel_item        save_txt = (Panel_item) xv_get(dir_list, XV_KEY_DATA, KEY_SAVE_TXT);
  226.  
  227.     xv_set(save_btn,
  228.         PANEL_INACTIVE,        TRUE,
  229.         NULL);
  230.     xv_set(save_txt,
  231.         PANEL_INACTIVE,        TRUE,
  232.         NULL);
  233. #endif    USE_SAVE
  234.     if (!parent)
  235.     {
  236.         xv_set(bookmark_mi,
  237.             MENU_INACTIVE,                    TRUE,
  238.             NULL);
  239.         xv_set(show_info_mi,
  240.             MENU_INACTIVE,                    TRUE,
  241.             NULL);
  242.     }
  243. }
  244.  
  245.  
  246. //***************************************************************************
  247. // void GWDirectory::row_select(int, Response *)
  248. //
  249. void GWDirectory::row_select(int, Response *)
  250. {
  251. #if        USE_SAVE
  252.     //
  253.     // Show the button and the text item if the selected item is savable
  254.     //
  255.     if (strchr("09", resp->get_type()))
  256.     {
  257.         Panel_item        save_btn = (Panel_item) xv_get(dir_list, XV_KEY_DATA, KEY_SAVE_BTN);
  258.         Panel_item        save_txt = (Panel_item) xv_get(dir_list, XV_KEY_DATA, KEY_SAVE_TXT);
  259.  
  260.         xv_set(save_btn,
  261.             PANEL_INACTIVE,        FALSE,
  262.             NULL);
  263.         xv_set(save_txt,
  264.             PANEL_INACTIVE,        FALSE,
  265.             NULL);
  266.     }
  267. #endif    USE_SAVE
  268.     xv_set(show_info_mi,
  269.         MENU_INACTIVE,                    FALSE,
  270.         NULL);
  271.     xv_set(bookmark_mi,
  272.         MENU_INACTIVE,                    FALSE,
  273.         NULL);
  274. }
  275.  
  276.  
  277. //***************************************************************************
  278. // void GWDirectory::display()
  279. //
  280. void GWDirectory::display()
  281. {
  282.     gopher->start_get();
  283.     int        i = 0;
  284.     char    *str;
  285.  
  286.     frame_unbusy(frame);
  287.     xv_set(dir_list,
  288.         XV_SHOW,                    FALSE,
  289.         NULL);
  290.     while (str = gopher->get_next())
  291.     {
  292.         Response    *r = new Response(str);
  293.         xv_set(dir_list,
  294.             PANEL_LIST_INSERT,            i,
  295.             PANEL_LIST_STRING,            i, r->get_title(),
  296.             PANEL_LIST_GLYPH,            i, get_image(r->get_type()),
  297.             PANEL_LIST_CLIENT_DATA,        i, r,
  298.             NULL);
  299.         i++;
  300.     }
  301.     xv_set(dir_list,
  302.         XV_SHOW,                    TRUE,
  303.         NULL);
  304. }
  305.  
  306.  
  307. #if        USE_SAVE
  308. //***************************************************************************
  309. // void GWDirectory::save_notify(Panel_item item, Event *event)
  310. //
  311. void GWDirectory::save_notify(Panel_item item, Event *event)
  312. {
  313.     event = event;
  314.     GWDirectory        *gwindow = (GWDirectory *) xv_get(item, XV_KEY_DATA, KEY_GWINDOW);
  315.     Panel_item        save_txt = (Panel_item) xv_get(item, XV_KEY_DATA, KEY_SAVE_TXT);
  316.  
  317.     char    *filename = (char *) xv_get(save_txt, PANEL_VALUE);
  318. }
  319. #endif    USE_SAVE
  320.  
  321.  
  322. //***************************************************************************
  323. // void GWDirectory::menu_proc(Menu menu, Menu_item mi)
  324. //
  325. void GWDirectory::menu_proc(Menu menu, Menu_item mi)
  326. {
  327.     GWDirectory        *gwindow = (GWDirectory *) xv_get(menu, XV_KEY_DATA, KEY_GWINDOW);
  328.     char            *item = (char *) xv_get(mi, MENU_STRING);
  329.  
  330.     if (strcmp(item, "Bookmarks...") == 0)
  331.     {
  332.         bookmarks->show();
  333.     }
  334.     else if (strcmp(item, "Preferences...") == 0)
  335.     {
  336.         //
  337.         // Build a preferences window
  338.         //
  339.         gwpref->show();
  340.     }
  341.     else if (strcmp(item, "About...") == 0)
  342.     {
  343.         //
  344.         // Build an About window
  345.         //
  346.         GWAbout    *about = new GWAbout(gwindow->frame);
  347.         about->open(NULL);
  348.     }
  349.     else if (strcmp(item, "Another Gopher...") == 0)
  350.     {
  351.         //
  352.         // Get information from the user about where to contact
  353.         // a new gopher server.
  354.         //
  355.         GWGopher    *newgopher = new GWGopher(gwindow->frame);
  356.         newgopher->open(gwindow->info);
  357.     }
  358. }
  359.  
  360.  
  361. //***************************************************************************
  362. // void GWDirectory::set_bookmark_proc(Menu menu, Menu_item mi)
  363. //
  364. void GWDirectory::set_bookmark_proc(Menu menu, Menu_item mi)
  365. {
  366.     GWDirectory        *gwindow = (GWDirectory *) xv_get(mi, XV_KEY_DATA, KEY_GWINDOW);
  367.  
  368.     menu = menu;
  369.     if (gwindow->current_selected == -1)
  370.     {
  371.         //
  372.         // No row is selected.  We will assume we want to add a bookmark pointing to the
  373.         // current directory.  This is simple since we already have a Response object
  374.         // for ourselves.
  375.         //
  376.         bookmarks->add(new Response(gwindow->info));
  377.     }
  378.     else
  379.     {
  380.         //
  381.         // Some row was selected.  This is cool.  All we need to do now is retrieve the
  382.         // data associated with that row and add it to the bookmark list.
  383.         //
  384.         Response        *r;
  385.         r = (Response *) xv_get(gwindow->dir_list, PANEL_LIST_CLIENT_DATA, gwindow->current_selected);
  386.         bookmarks->add(new Response(r));
  387.     }
  388. }
  389.  
  390.  
  391.  
  392.